package com.mopencode.seckill.controller;

import com.lxs.legou.common.utils.DateUtil;
import com.lxs.legou.core.controller.BaseController;
import com.mopencode.seckill.po.SeckillGoods;
import com.mopencode.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author Mcb
 * @date 2022/4/9
 * @apiNote 秒杀商品接口
 */
@RestController
@RequestMapping("/seckillgoods")
@CrossOrigin
public class SeckillGoodsController extends BaseController<SeckillGoodsService, SeckillGoods> {

    @Autowired
    private SeckillGoodsService seckillGoodsService;

    /**
     * 返回当前时间起，相互隔两小时的五个时间段
     *
     * @return
     */
    @RequestMapping("/menus")
    public List<Date> dateMenus() {
        return DateUtil.getDateMenus();
    }

    @RequestMapping("/list/{time}")
    public List<SeckillGoods> list(@PathVariable("time") String time) {
        return seckillGoodsService.list(time);
    }

    /**
     * 根据时区和id查询秒杀商品
     *
     * @param time
     * @param id
     * @return
     */
    @RequestMapping("/one")
    public SeckillGoods one(String time, Long id) {
        return seckillGoodsService.one(time, id);
    }
}
